package com.weather.web.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.enums.BusinessType;
import com.weather.business.domain.NmOfficialWebsite;
import com.weather.business.service.INmOfficialWebsiteService;
import com.weather.common.utils.poi.ExcelUtil;
import com.weather.common.core.page.TableDataInfo;

/**
 * 地方官网政策Controller
 *
 * @author ruoyi
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/business/website")
public class NmOfficialWebsiteController extends BaseController
{
    @Autowired
    private INmOfficialWebsiteService nmOfficialWebsiteService;

    /**
     * 查询地方官网政策列表
     */
    @PreAuthorize("@ss.hasPermi('business:website:list')")
    @GetMapping("/list")
    public TableDataInfo list(NmOfficialWebsite nmOfficialWebsite)
    {
        startPage();
        List<NmOfficialWebsite> list = nmOfficialWebsiteService.selectNmOfficialWebsiteList(nmOfficialWebsite);
        return getDataTable(list);
    }

    /**
     * 导出地方官网政策列表
     */
    @PreAuthorize("@ss.hasPermi('business:website:export')")
    @Log(title = "地方官网政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NmOfficialWebsite nmOfficialWebsite)
    {
        List<NmOfficialWebsite> list = nmOfficialWebsiteService.selectNmOfficialWebsiteList(nmOfficialWebsite);
        ExcelUtil<NmOfficialWebsite> util = new ExcelUtil<NmOfficialWebsite>(NmOfficialWebsite.class);
        util.exportExcel(response, list, "地方官网政策数据");
    }

    /**
     * 获取地方官网政策详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:website:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nmOfficialWebsiteService.selectNmOfficialWebsiteById(id));
    }

    /**
     * 新增地方官网政策
     */
    @PreAuthorize("@ss.hasPermi('business:website:add')")
    @Log(title = "地方官网政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NmOfficialWebsite nmOfficialWebsite)
    {
        return toAjax(nmOfficialWebsiteService.insertNmOfficialWebsite(nmOfficialWebsite));
    }

    /**
     * 修改地方官网政策
     */
    @PreAuthorize("@ss.hasPermi('business:website:edit')")
    @Log(title = "地方官网政策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NmOfficialWebsite nmOfficialWebsite)
    {
        return toAjax(nmOfficialWebsiteService.updateNmOfficialWebsite(nmOfficialWebsite));
    }

    /**
     * 删除地方官网政策
     */
    @PreAuthorize("@ss.hasPermi('business:website:remove')")
    @Log(title = "地方官网政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nmOfficialWebsiteService.deleteNmOfficialWebsiteByIds(ids));
    }
}
